<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
 $con = mysql_connect("localhost","root","");

if(!$con)
{
    die('Could not connect:' . mysql_error());
}
mysql_select_db("db_name",$con);
function SignUp($username, $password,$first_name, $Last_name)
{
     $result = mysql_query("INSERT INTO Members(username, password, first_name, last_name)
     VALUES ('$username','$password','$first_name','$Last_name'") or die(mysql_error()); 
}

function SignIn($username, $password , $count)
{
    $result = mysql_query("SELECT * FROM Members Where username='$username' AND password='$password')") or die(mysql_error());
    $output = mysql_query($result);
    $count = mysql_num_rows($output);
    if($count == 1)
    {
        session_register("$username");
        session_register("$password");
        header("location:search.php");    
    }
    else
    {
        echo "wrong username or password";
    }
}

function Insert($text, $authorname)
        {
          $result = mysql_query("INSERT INTO Texts(text, author_username , dateadded)
          VALUES ('$text','$authorname','NOW()'") or die(mysql_error()); 
          
        }
        
function ViewText()
        {
           $result = mysql_query("SELECT * FROM Texts ordered by dateadded") or die(mysql_error()); 
   
           while($row = mysql_fetch_assoc($result))
          
             echo $row['author_username'] ;
             echo "<br />";
             echo $row['text'];
               
             echo "<br />";
             echo "<br />";
            
        }
        
Function Delete($deleteid)
        {
            $result = mysql_query("DELETE FROM Texts where textid = $deleteid") or die(mysql_error()); 
        }
        
Function SearchByAuthor($authorNeeded)
        {
                $searchauthor = mysql_query("Select * 
                From Texts t inner join Members m 
                on  t.author_username = m.username 
                where t.author_username = '$authorNeeded';") or die(mysql_error());


                While($row = mysql_fetch_assoc($searchauthor))
                    {
                         echo $row['text'] . "-".  $row['author_username'] . "-". $row['date_added'];
                    }
         }
         
function SearchByDate($dateNeeded) 
 {
                $searchdate = mysql_query("Select * 
                From Texts t inner join Members m 
                on  t.author_username = m.username 
                where t.datea_dded = '$dateNeeded';") or die(mysql_error());;


       While($row = mysql_fetch_assoc($searchdate))
        {
            echo $row['text'] . "-".  $row['author_username'] . "-". $row['date_added'];
        }
 }
 mysql_close($con);
        ?>
    </body>
</html>
